1. Field of the Invention
The present invention generally relates to an image decoding method, in particular, to a progressive JPEG image decoding method.
2. Description of Related Art
According to the joint photographic experts group (JPEG) compression technique based on progressive discrete cosine transformation (DCT), an image is encoded by scanning the entire image several times so that the encoded JPEG data stream contains the data of a plurality of scan layers. Accordingly, while decoding the image, data of all these scan layers has to be decoded to re-establish the original image. Moreover, since each of the scan layers carries part of the characteristics of the original image, the image decoded from each scan layer roughly presents the original image, and the quality of the decoded image is increased along with the number of decoded scan layers.
FIG. 1 illustrates a conventional progressive JPEG image decoding apparatus. Referring to FIG. 1, the decoding apparatus 100 includes a variable length decoding (VLD) apparatus 110, a memory apparatus 120, an inverse quantizer 130, and an inverse DCT (IDCT) apparatus 140. The decoding apparatus 100 processes a decoding procedure based on progressive DCT, and the decoding procedure will be described below.
First, an encoded JPEG data is processed by the VLD apparatus 110. Since the information of a previous scan layer has be to referred when the VLD apparatus 110 processes each scan layer, the processing result has to be stored in the memory apparatus 120 having the same size as the image to be used by the VLD apparatus 110 for processing the next scan layer. All the coefficients of a scan layer collected by the memory apparatus 120 are sequentially sent to the inverse quantizer 130 and the IDCT apparatus 140 so that an inverse quantization and an IDCT are performed thereto to obtain the decoded pixels and re-establish the progressive image. In the method described above, the size of the image is restricted by the memory space even though the image can present the progressive characteristic. Accordingly, the efficiency in the usage of the memory space has to be improved.
A progressive JPEG image decoding method is provided by U.S. Pat. No. 7,313,281, wherein some decoded pixels of an image and a non-zero history table are generated for each scan layer, and the decoded pixels generated by each scan layer are accumulated in a predetermined order, and the non-zero history table generated by each scan layer is updated. In foregoing method, memory space is saved by referring to non-zero history records. However, the non-zero history records can only be used as reference during Huffman decoding, while before accumulating the decoded coefficients of each scan layer, the previous decoding result at the same address still has to be referred in order to perform a power of two adjustment to the decoded coefficients and obtain correct decoded coefficients.
For example, a value −9 is expressed as 11110111 in 8 binary bits. However, it is the absolute value of −9 which is encoded during Huffman encoding, namely, |−9|=(00001001). If bits 7˜3 (among bits 0˜7) are encoded first and then the other bits are encoded one by one, the first encoding process encodes the first 5 bits (00001) and 0 (0 is negative and 1 is positive), the second encoding process encodes 0, the third encoding process encodes 0, and the fourth encoding process encodes 1. Accordingly, when a decoder receives the first data, it understands from the bit value 0 that this is a negative value, thus, a signed power of two adjustment is performed to (00001), wherein the complement of (00001) is first obtained as (11110), and a power of two calculation is then performed to the complement (11110) to obtain (11110000). Next, the results of the second and the third decoding processes are both 0, which means the values are both null, and the result of the fourth decoding process is 1, which means the value is not null, then the binary value of −1 is obtained as (11111111) according to the negative sign recorded in a sign table. However, because the bit corresponding to the scan layer decoded in the fourth decoding process is bit 0, foregoing result (11111111) has to be shifted 0 bit leftward to obtain (111111111), which denotes value −1. After adding all the decoded values, the decoded coefficient −9 is eventually obtained as (11111000)+0+0+(111111111)=(11110111) and the decoding operation is completed. However, in U.S. Pat. No. 7,313,281, the power of two adjustment to the accumulated value is not provided, thus, decoding error may be caused so that incorrect image may be presented.